<!DOCTYPE html>
<html>
     <head>
          <meta charset="utf-8">
          <title></title>
     </head>
     <body>
          <div id="app">
               <button type="button" name="button" @click="apiVal2">获取</button>
               {{val}}
          </div>
     </body>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script type="text/javascript">

     var app=new Vue({
          el:"#app",
          data:{
               val:"1"
          },
          methods:{
               getVal:function(){
                    axios.get('http://192.168.3.67/dc2/index.php/home/index/ajax_getdashi'
                    ,{
                         params: {
                              Ipage: 2
                         }
                    })
                    .then(function (response) {
                         app.val=response.data['0'].abstract
                         console.log(response);
                    })
                    .catch(function (error) {
                         console.log(error);
                    });
               },
               postVal:function(){
                    axios.post('http://192.168.3.67/dc2/index.php/home/index/ajax_getdashi'
                    ,{
                         Ipage: 2
                    })
                    .then(function (response) {
                         app.val=response.data['0'].abstract
                         console.log(response);
                    })
                    .catch(function (error) {
                         console.log(error);
                    });
               },
               apiVal:function(){//普通表单模式
                    axios({
                         url: 'http://192.168.3.67/dc2/index.php/home/index/ajax_getdashi',
                         method: 'post',
                         data: {
                              Ipage:2
                         },
                         transformRequest: [function (data) {
                              let ret = ''
                              for (let it in data) {
                                   ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                              }
                              return ret
                         }],
                         headers: {
                           'Content-Type': 'application/x-www-form-urlencoded'
                         }
                    })
                    .then(function (response) {
                         app.val=response.data['0'].abstract
                         console.log(response);
                    })
                    .catch(function (error) {
                         console.log(error);
                    });
               },
               apiVal2:function(){//默认异步头模式，Content-Type为text/plain;charset=UTF-8，而请求表单参数在RequestPayload中。
                    axios({
                         url: 'http://192.168.3.67/dc2/index.php/home/index/ajax_getdashi',
                         method: 'post',
                         data: {
                              Ipage:2,
                              tge:"123abc"
                         },
                    })
                    .then(function (response) {
                         app.val=response.data['0'].abstract
                         console.log(response);
                    })
                    .catch(function (error) {
                         console.log(error);
                    });
               }
               /*
               则PHP中需要通过数据流方式处理参数
               $dd=file_get_contents('php://input');
               if($dd){
                    $dd=urldecode($dd);
                    $dd=json_decode($dd,true);//得到参数数组
               }
               */

          }
     })
</script>
</html>
